Skip to content

Conversation

@redstrate
Copy link
Contributor

@redstrate redstrate commented Dec 11, 2025

Right now you can set the mouse cursor shape in a TouchArea to a
pre-defined list of cursor shapes, but sometimes you have your own
custom cursor set for actions that aren't in the CSS spec.

This change introduces new API to set a mouse cursor to an Image, using
the same property (mouse-cursor) and a changeable hotspot.

Example

TouchArea {
    width: parent.width;
    height: parent.height;
    mouse-cursor: custom(@image-url("close.png"), 0, 0);
}

TODO

  • Clean up the code, obviously
  • Link to existing issue/discussion
  • Check documentation, add docs for custom cursors
  • Add support for winit (maybe rebasing on top of https://github.com/slint-ui/slint/pull/6923/files and adding the suggestions)
  • Review the API (should specifying a hotspot be optional, for example)
  • Add unit tests for cpp/rust code generators and interpreter

@redstrate redstrate force-pushed the work/josh/custom-cursor branch 3 times, most recently from 18350b2 to 80b3462 Compare December 11, 2025 22:24
@redstrate redstrate force-pushed the work/josh/custom-cursor branch from 80b3462 to 1768401 Compare December 12, 2025 16:13
@redstrate redstrate force-pushed the work/josh/custom-cursor branch from cf4124f to d50c6ac Compare December 12, 2025 16:23
@redstrate
Copy link
Contributor Author

There is still some stuff in the TODO like documentation, but now that it works I would like some input on:

  • Does the API make sense? Should the hotspot x/y be optional? Right now they aren't.
  • Does the approach make sense? This is my first time doing a major Slint compiler/generator change, so :)

@redstrate redstrate marked this pull request as ready for review December 12, 2025 16:26
@NigelBreslaw
Copy link
Member

@redstrate There are quite a few people on vacation at the moment so replies/help might be slow till 2026 rolls around.

@redstrate redstrate force-pushed the work/josh/custom-cursor branch from d50c6ac to e4c102f Compare December 16, 2025 16:02
Copy link
Member

@ogoffart ogoffart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is great work so far.
I'm on vacation at the moment but I just had a look over this PR anyway.

One thing I wonder is what to do with regard to scale factor. Especially when rendering SVG, we should probably take it into account.

NeswResize,
/// Bidirectional resize north-west-south-east.
NwseResize,
/// Custom cursor from an `Image`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should document what the hotspot is and relative to what.

#[non_exhaustive]
#[repr(C, u32)]
#[derive(Debug, Clone, PartialEq, Default)]
pub enum MouseCursor {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when this was in the enums.rs macro, it got also automatic documentation in there: https://docs.slint.dev/latest/docs/slint/reference/gestures/toucharea/#mouse-cursor
Now, the documentation need to be written manually and kept in sync.
I wonder if it wouldn't be good to put that enum in i_slint_common, so it can be enumerated to generate the docs and avoid repetition in lookup.rs.

)
}
}
Expression::MouseCursor(MouseCursor::Default) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we would used strnum macros to simplify this. (same in rust)

Right now you can set the mouse cursor shape in a TouchArea to a
pre-defined list of cursor shapes, but sometimes you have your own
custom cursor set for actions that aren't in the CSS spec.

This change introduces new API to set a mouse cursor to an Image, using
the same property (mouse-cursor) and a changeable hotspot.
@redstrate redstrate force-pushed the work/josh/custom-cursor branch from 9aabd3a to b902e48 Compare January 16, 2026 19:33
}

#[derive(Clone, Debug, Default)]
pub enum MouseCursor {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yet another place where MouseCursor is duplicated 😬 This is because there's two different Expression types here, maybe I can use generics here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants